using System;
using NHibernateDemo.Core;
using NHibernate.Event;
using NHibernate.Event.Default;

namespace NHibernateDemo.DAL
{
    public class UpdateTimeListener : DefaultSaveEventListener
    {        

        
        protected override object PerformSaveOrUpdate(SaveOrUpdateEvent saveOrUpdateEvent)
        {
            
          if (saveOrUpdateEvent.Entity is IAuditableEntity)
          {
              Console.WriteLine("Logging ..." + saveOrUpdateEvent.EntityName);
              (saveOrUpdateEvent.Entity as IAuditableEntity).UpdateDate = DateTime.Now;
          }

          return base.PerformSaveOrUpdate(saveOrUpdateEvent);
        }        
    }
}
